
OBJCOPY_INST = /d/xpack/bin/riscv-none-elf-objcopy -j .text -j .text.startup -j .text.init -O binary 
OBJCOPY_DATA = /d/xpack/bin/riscv-none-elf-objcopy -j .data -j .rodata -j .bss -j .sbss -O binary 

ELFS := $(wildcard elf/*.elf)
DATAS := $(patsubst elf/%.elf,data/%.data,$(ELFS))
INSTS := $(patsubst elf/%.elf,inst/%.inst,$(ELFS))
IHEX := $(patsubst elf/%.elf,ihex/%_00.dat,$(ELFS))
DHEX := $(patsubst elf/%.elf,dhex/%_00.dat,$(ELFS))

all: $(DATAS) $(INSTS) $(IHEX) $(DHEX)

data/%.data: elf/%.elf
	$(OBJCOPY_DATA) $< $@

inst/%.inst: elf/%.elf
	$(OBJCOPY_INST) $< $@

ihex/%_00.dat: inst/%.inst
	python3 inst.py $<

dhex/%_00.dat: data/%.data
	python3 data.py $<

clean:
	rm -f inst/* data/* ihex/* dhex/* cnt/*.icnt cnt/*.dcnt isim/* dsim/*

